// myself/login/ModifyPassword.js
import api from '../../utils/api.js';
import utils from '../../utils/utils.js';
import wechat from '../../utils/wechat.js';
import network from '../../utils/network.js';
import notification from '../../utils/notification_center.js'
let app = getApp();
let userInfo = null;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    finish: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.toast = this.selectComponent("#toast");
  },

  formSubmit(e) {
    if (!e.detail.value.old_pass) {
      this.toast.showToast('请输入原密码');
      return;
    }
    if (!e.detail.value.new_pass) {
      this.toast.showToast('请输入新密码');
      return;
    }
    if (!e.detail.value.new_2_pass) {
      this.toast.showToast('请输入确认密码');
      return;
    }
    if (e.detail.value.new_pass != e.detail.value.new_2_pass) {
      this.toast.showToast('新密码与确认密码不匹配');
      return;
    }

    network.postJson(this, api.editpass, {
      token: app.globalData.userInfo.token,
      adminid: app.globalData.userInfo.uid,
      passoldPost: e.detail.value.old_pass,
      passwordPost: e.detail.value.new_pass
    }).then(res => {
      this.toast.showToast('密码修改成功');
      wx.navigateBack();
    })
  }
})